<?php View::render('admin/layouts/meta');?>
<style>
    .j-u-del1{position:absolute;right:-0.6rem;top:-0.6rem;font-size:1.2rem;color:#dd514c;margin-top: 8px;}
    .j-u-del1:hover{text-decoration: none;color:#dd514c;}
</style>
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl(); ?>/assets/js/webuploader.css" />
<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分享内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea class="input-text" style="width:100%;height:150px"  placeholder="" readonly name="detail"><?php echo $details['content'] ? $details['content'] : ''; ?></textarea>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分享图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="clearfix">
                    <div id="j-file-avatar" class="">
                        <?php if ($info && $info['image_list']) {$imageList = explode(',', $info['image_list']);foreach ($imageList as $image) {?>
                            <div class="f-l mr-10 j-u-box">
                                <a href="javascirpt:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>
                                <input type="hidden" name="image_list[]" value="<?php echo $image; ?>" />
                                <a href="javascript:;"><img class="thumbnail" src="<?php echo $image; ?>"  style="width:100px;height:100px" /></a>
                            </div>
                        <?php }}?>
                    </div>
                </div>
                <span>图片大小:320px*640px</span>
            </div>
        </div>


        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" name="experienceId" value="<?php echo $details ? $details['id'] : 0; ?>" />
                <input class="btn btn-primary radius" type="button" id="j_submit" value="&nbsp;&nbsp;审核通过&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
</body>
<?php View::render('admin/layouts/footer');?>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/ueditor.config.js?v=123"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/ueditor.all.min.js?v=123"> </script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js?v=123"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/assets/js/webuploader.min.js"></script>
<script type="text/javascript">
    $(function(){
        formData = {}
        $.getJSON('/oss/getImageToken', function(ret){
            var data = ret.data;
            formData = {
                'key' : data.dir,
                'policy': data.policy,
                'OSSAccessKeyId': data.accessid,
                'success_action_status' : '200', //让服务端返回200,不然，默认会返回204
                'callback' : '',
                'signature': data.signature,
                'domain': data.domain,
                'host':data.host
            };
        });
        $('#j_submit').click(function(){
            var $btn = $(this);
            $btn.button('loading');
            $.post('<?php echo Router::getBaseUrl(); ?>/admin_experience/details', $('form').serialize(), function (result) {
                if (result.status == 200) {
                    layer.msg(result.msg, {
                        icon: 1,
                        skin: 'u-msg',
                        time: 1800,
                    }, function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                    $btn.button('reset');
                    return true;
                }
                layer.msg(result.msg, {
                    icon: 0,
                    skin: 'u-msg',
                    time: 3000,
                }, function () {

                });
                $btn.button('reset');
            }, 'json');
            return;
        });
        var max_file = 1000, $list = $('#j-file');
        var uploader = WebUploader.create({
            auto:true,
            swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
            server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/file',
            pick: '#j-upload',
            formData:formData,
            resize: true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });
        uploader.on('beforeFileQueued', function(file){
            formData.key += random_string(15)+get_suffix(file.name);
            uploader.options.server = formData.host;
            uploader.options.formData = formData;
        });

        uploader.on( 'uploadError', function( file ) {
            layer.msg('文件上传出错', {
                icon: 0,
                skin: 'u-msg',
                time: 3000,
            });
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            img = formData.domain+'/'+formData.key;
            var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="image" value="'+img+'" />\
                    <img class="thumbnail1" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
            $list.html(tpl);
            $('.j-u-del').on('click', function(){
                $(this).parent('div').remove();
            });
        });
        var max_file = 1000, $list1 = $('#j-file-thumbnail');
        var uploaders = WebUploader.create({
            auto:true,
            swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
            server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/file',
            pick: '#j-upload-thumbnail',
            formData:formData,
            resize: true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });
        uploaders.on('beforeFileQueued', function(file){
            formData.key += random_string(15)+get_suffix(file.name);
            uploaders.options.server = formData.host;
            uploaders.options.formData = formData;
        });

        uploaders.on( 'uploadError', function( file ) {
            layer.msg('文件上传出错', {
                icon: 0,
                skin: 'u-msg',
                time: 3000,
            });
        });

        uploaders.on( 'uploadSuccess', function( file,response) {
            img = formData.domain+'/'+formData.key;
            var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="thumbnail" value="'+img+'" />\
                    <img class="thumbnail" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
            $list1.html(tpl);
            $('.j-u-del').on('click', function(){
                $(this).parent('div').remove();
            });
        });
        $('.j-u-del').on('click', function(){
            $(this).parent('div').remove();
        });
        var max_file = 100, $list_avatar = $('#j-file-avatar');
        var uploader_avatar = WebUploader.create({
            auto:true,
            swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
            server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/file',
            pick: '#j-upload-avatar',
            formData:formData,
            resize: true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });
        uploader_avatar.on('beforeFileQueued', function(file){
            formData.key += random_string(15)+get_suffix(file.name);
            uploader_avatar.options.server = formData.host;
            uploader_avatar.options.formData = formData;
        });

        uploader_avatar.on( 'uploadError', function( file ) {
            layer.msg('文件上传出错', {
                icon: 0,
                skin: 'u-msg',
                time: 3000,
            });
        });

        uploader_avatar.on( 'uploadSuccess', function( file,response) {
            img = formData.domain+'/'+formData.key;
            var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="image_list[]" value="'+img+'" />\
                    <img class="thumbnail" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
            $list_avatar.append(tpl);
            $('.j-u-del').on('click', function(){
                $(this).parent('div').remove();
            });
        });

        var ue = UE.getEditor('editor');
    });

</script>
</html>